<?php
require_once './config.php';

$key = $_REQUEST['key'];
$page = $_REQUEST['page'];
$size = $_REQUEST['size'];
$skip = ($page-1)*$size;
$sort = $_REQUEST['sort'];
$type = $_REQUEST['type'];
$sql = "SELECT * FROM goodsinfo where gname like '%$key%' order by $sort $type limit $skip,$size";

$result = mysqli_query($conn,$sql);

$obj = array(
    'code' => 1,
    "msg" => 'success'
);

while($data = mysqli_fetch_assoc($result)){
    $arr[] = $data;
}
$obj['data'] = $arr;

$spl = "SELECT count(*) from goodsinfo WHERE gname LIKE '%$key%'";

$result = mysqli_query($conn,$spl);

$data = mysqli_fetch_assoc($result);

$obj['count'] = $data['count(*)'];

echo json_encode($obj);